﻿#pragma once

#include <QObject>
#include <QSerialPort>
#include <QByteArray>
#include <QDataStream>
#include <QVector>
#include <QThread>
#include <QTimer>

#include "GlobalDefine.h"
#include "CoreData.h"

class SendMsgWorker : public QObject
{
	Q_OBJECT

public:
	explicit SendMsgWorker(QVector<QByteArray> &dataVec, QSerialPort &serialPort, QObject *parent = nullptr);
	~SendMsgWorker();

	quint16 calculateCRC16(const QByteArray &data);

	void startTimer(unsigned long time);

public slots:
	void sendInitData();
	void cycleWork();

signals:
	void finished();
	void updateLastSendArr(QByteArray arr);
	void startCycleTimer();

private:
	void initCycleWork();

	void sendReadBatteryInfoByteArray();
	void sendReadBatteryDetailInfoByteArray();

private:
	QVector<QByteArray> &m_dataVec;
	QSerialPort &m_serialPort;

	QTimer *m_timer;
};
